package org.zjx.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Objects;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Address implements Serializable {
    private static final long serialVersionUID = 1L;
    private String city;
    private int x;
    private int y;

    // 重写 equals 方法
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Address address = (Address) o;
        return x == address.x && y == address.y && Objects.equals(city, address.city);
    }

    // 重写 hashCode 方法
    @Override
    public int hashCode() {
        return Objects.hash(city, x, y);
    }

    public boolean near(Address otherAddress, int off) {
        return this.city.equals(otherAddress.city) && Math.abs(x - otherAddress.x) <= off && Math.abs(y - otherAddress.y) <= off;
    }

}
